var app = getApp();
var api = require('../../api.js');
var util = require('../../utils/util.js');

var myreg = /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/;
Page({
  data: {
    company: [],
    index: 0,
    date: '2000-09-01',
  },
  forget_password: function() {
    wx.navigateTo({
      url: '/pages/login/forget',
    })

  },
  bindDateChange: function(e) {
    this.setData({
      birthday: e.detail.value
    })
  },

  formSubmit: function(e) {
    var info = e.detail.value;
    if (info.name.length <= 0) {
      wx.showToast({
        title: '请输入正确您的姓名',
        icon: 'none'
      })
    } else if (info.phone.length != 11) {
      wx.showToast({
        title: '请输入正确的手机号码',
        icon: 'none'
      })
    } else {

      app.ajax(api.edit_info, {
        member_id: this.data.id,
        name: info.name,
        phone: info.phone,
        birthday: info.birthday,
        rd_session: wx.getStorageSync('rd_session')
      }, (res) => {

        if (res.result == 'success') {
          wx.showToast({
            title: '修改成功！',
            icon: 'none',
            duration: 200,
            mask: true,
            success: function(res) {
              wx.navigateBack({
                delta: 1,
              })
            },
          })
        }
      })
    }
  },
  onLoad: function() {
    var rd_session = wx.getStorageSync('rd_session');

    // 获取信息
    app.ajax(api.member_info, {
      rd_session: wx.getStorageSync('rd_session')
    }, (res, err) => {

      this.setData({
        info: res.data.lists,
        id: res.data.lists.id,
        birthday: res.data.lists.birthday
      })

    })
  }
});